<template>
  <div class="upgrade-wrap">
    <el-form v-model="form">
      <el-form-item>
        <span>设置金额：</span>
        <el-input v-model="form.price" type="text" class="input-price"/>
      </el-form-item>
    </el-form>
    <el-row class="row">
      <el-button type="primary" @click="handleSetting">确定</el-button>
    </el-row>
  </div>
</template>
<script>
import { update, findChild } from '@/api/data'
export default {
  name: 'BasicUpgrade',
  data() {
    return {
      form: {
        price: ''
      }
    }
  },
  created() {
    this.getFind()
  },
  methods: {
    handleSetting() {
      const flag = this.check()
      flag ? this.modification() : ''
    },
    check() {
      const price = this.form.price
      if (price.trim() === '') {
        this.$message.warning({
          duration: 1000,
          message: '价格不能为空'
        })
        return false
      }
      return true
    },
    modification() {
      const name = this.form.price
      const id = '12'
      update(id, name)
        .then((res) => {
          if (res.success) {
            this.$message.success({
              duration: 1000,
              message: '设置成功'
            })
          }
        }).catch((e) => {
          this.$message.warning({
            duration: 1000,
            message: '请稍后再试'
          })
        })
    },
    getFind() {
      findChild('11')
        .then((res) => {
          console.log(res)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.upgrade-wrap {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  .input-price {
    width: 200px;
  }
}
</style>
